package com.lognsoft.btest;

import java.util.ArrayList;
import java.util.HashMap;
import java.lang.String;

public class ReportGen 
{
	private class TestCaseLog
	{
		public TestCaseLog(String s,boolean b) { strCase = s; ret = b; }
		public String strCase;
		public boolean ret;
	};

	private class TestSuiteLog extends ArrayList<TestCaseLog>
	{
		private static final long serialVersionUID = -7957991425156227399L;
		public String strBasePath;	
		public int Success = 0;
		public int failed = 0;
	};

    HashMap<String, TestSuiteLog> TestSuites = 
    		new HashMap<String, TestSuiteLog>();
    ArrayList<String> TestSuitesName = new ArrayList<String>();

    int Success = 0;
    int failed = 0;
    int Count = 0;
    
    public void print()
    {
    	System.out.println(
    		"Count = " + Count + 
    		", Success = " + Success + 
    		", Failed = " + failed);
    	
    	System.out.println ("Test Suites :");
    	
    	for (int i = 0; i < TestSuitesName.size(); i++)
    	{
    		String s = TestSuitesName.get(i);
    		TestSuiteLog ts = TestSuites.get(s);
   
    		System.out.println (
    				"No " + (i+1) + 
    				": Path = " + s + 
    				" (Count = "+ts.size()+
    				", Success = " +ts.Success + 
    				", Failed = " + ts.failed + 
    				")" );

    	}
    	if (failed > 0)
    	{
    		int FN = 1;
    		
    		for (int i = 0; i < TestSuitesName.size(); i++)
    		{
    	   		String s = TestSuitesName.get(i);
        		TestSuiteLog ts = TestSuites.get(s);
        		if (ts.failed == 0) continue;
        		
        		System.out.println("Test Suite Path = " + ts.strBasePath );
        		
        		for (int k = 0; k < ts.size(); k++)
        		{
        			TestCaseLog tc = ts.get(k);
        			
        			if (tc.ret) continue;
        			
        			System.out.println ("No " + (FN++) + ": " + tc.strCase);
        		}
    		}
    	}
    }

public void addResult (String path, String testCase, boolean ret)
{
	String TSName = FileOp.relative_path (path);

	if (TSName.length() > 0)
	{
		TSName = TSName.substring (0, TSName.length() - 1);
	}
	
	TestSuiteLog ts = TestSuites.get (TSName);

	if (ts == null)
	{
		ts = new TestSuiteLog ();
		ts.strBasePath = TSName;
		TestSuites.put (TSName, ts);
		TestSuitesName.add (TSName);
	}
	
	int ind = testCase.indexOf('.');
	
	ts.add( 
		new TestCaseLog(
			ind > 0 ? testCase.substring(0,ind) : testCase, 
			ret) 
	);
	
	if (ret)
	{
		ts.Success++;
		Success++;
	}
	else
	{
		ts.failed++;
		failed++;
	}
	
	Count++;
	
	return;
};

}
